home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libspool / pinfo.c.z / pinfo.c
C/C++ Source or Header  |  1996-05-06  |  4KB  |  153 lines

  1. /**************************************************************************
  2.  *                                      *
  3.  *           Copyright (c)    1991 Silicon Graphics, Inc.          *
  4.  *            All Rights Reserved                    *
  5.  *                                      *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI          *
  7.  *                                      *
  8.  * The copyright notice above does not evidence any actual of intended      *
  9.  * publication of such source code, and is an unpublished work by Silicon *
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or      *
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly *
  13.  * prohibited.                                  *
  14.  *                                      *
  15.  * RESTRICTED RIGHTS LEGEND:                          *
  16.  *                                      *
  17.  * Use, duplication or disclosure by the Government is subject to      *
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in      *
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,      *
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR      *
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of  *
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.      *
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311              *
  24.  **************************************************************************
  25.  *
  26.  * File: pinfo.c
  27.  *
  28.  * Description: Prints detailed information about the specified printer.
  29.  *
  30.  **************************************************************************/
  31.  
  32.  
  33. #ident "$Revision: 1.2 $"
  34.  
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #ifdef sgi
  40. #include <getopt.h>
  41. #endif
  42. #include "spool.h"
  43.  
  44.  
  45. char *pname;
  46. int spooler = SL_SPOOLER_NONE;
  47.  
  48.  
  49. extern char *optarg;
  50. extern int optind;
  51.  
  52.  
  53. void usage(char*);
  54. void print_info(SLPrinterStruct*);
  55.  
  56.  
  57. main(int argc, char *argv[])
  58. {
  59.     int ch;
  60.     int errflag = 0;
  61.     SLPrinterStruct *pinfo;
  62.  
  63.     /*
  64.      * Process command line args
  65.      */
  66.     while ((ch = getopt(argc, argv, "s:")) != -1) {
  67.     switch (ch) {
  68.         case 's':        /* Spooler to use */
  69.         if (!strcmp(optarg, "bsd"))
  70.             spooler = SL_SPOOLER_BSD;
  71.         else if (!strcmp(optarg, "sysv"))
  72.             spooler = SL_SPOOLER_SYSV;
  73.         else
  74.             errflag++;
  75.         break;
  76.         case '?':
  77.         default:
  78.         errflag++;
  79.         break;
  80.     }
  81.     }
  82.  
  83.     /*
  84.      * If error, print usage and exit
  85.      */
  86.     if (errflag) {
  87.     usage(argv[0]);
  88.     exit(1);
  89.     }
  90.  
  91.     /*
  92.      * If a spooling system has been specified set it
  93.      */
  94.     if (spooler != SL_SPOOLER_NONE) {
  95.     if (SLSetSpooler(spooler) < 0) {
  96.         SLPerror(argv[0]);
  97.         exit(1);
  98.     }
  99.     }
  100.  
  101.     /*
  102.      * Get the printer name
  103.      */
  104.     if (argc == optind) {
  105.     if (SLGetDefPrinterName(&pname) < 0) {
  106.         SLPerror(argv[0]);
  107.         exit(1);
  108.     }
  109.     } else
  110.     pname = argv[optind];
  111.  
  112.     /*
  113.      * Get the printer information
  114.      */
  115.     if (SLGetPrinterInfo(pname, &pinfo) < 0) {
  116.         SLPerror(argv[0]);
  117.         exit(1);
  118.     }
  119.  
  120.     /*
  121.      * Print the information
  122.      */
  123.     print_info(pinfo);
  124.  
  125.     return 0;
  126. }
  127.  
  128.  
  129. void usage(char *progname)
  130. {
  131.     (void)fprintf(stderr, "%s [-s bsd | sysv] [printer_name]\n", progname);
  132. }
  133.  
  134.  
  135. void print_info(SLPrinterStruct *ptr)
  136. {
  137.     (void)printf("\n");
  138.     (void)printf("\tName:\t\t%s\n", ptr->local_name);
  139.     (void)printf("\tFormal Name:\t%s\n", ptr->formal_name);
  140.     (void)printf("\tType:\t\t%s\n", ptr->type);
  141.     (void)printf("\tDefault:\t%s\n", (ptr->is_def) ? "Yes": "No");
  142.     (void)printf("\tClass:\t\t%s\n", (ptr->is_class) ? "Yes": "No");
  143.     if (ptr->is_networked) {
  144.     (void)printf("\tRemote host:\t%s\n", ptr->remote_host);
  145.     (void)printf("\tRemote name:\t%s\n", ptr->remote_name);
  146.     (void)printf("\tNetwork type:\t%s\n",
  147.              ptr->network_type ? ptr->network_type : "Unknown");
  148.     } else {
  149.     (void)printf("\tDevice:\t\t%s\n", ptr->dev);
  150.     }
  151. }
  152.  
  153.